<!DOCTYPE html>
<html lang="en">
<head>
    #include("../include/header.html")
</head>
<body>

<div class="container">
    #include("../include/menu.html")

    <!-- 工具栏 -->
    <div class="row" style="margin-bottom: 10px">
        <div class="col-sm-12">
            <div class="pull-left">
                <button class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="left"
                        onclick="add()" title="添加"><i class="fa fa-plus"></i> 添加
                </button>

                <!-- 增加按钮 -->
                <button class="btn btn-primary btn-sm " data-toggle="tooltip" data-placement="left"
                        onclick="refresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i> 刷新
                </button>
                <script type="text/javascript">
                    function add() {
                        window.location = pathPrefix + "/form";
                    }

                    function refresh() {//刷新
                        window.location = pathPrefix;
                    }
                </script>

            </div>
        </div>
    </div>

    <div class="row">
        <table id="paginationTable" class="table-hover"></table>
    </div>
</div>

#include("../include/footer.html")

<script>
    $(function () {
        $('#paginationTable').bootstrapTable({
            url: pathPrefix + '/getList',
            method: 'get',
            pagination: true,  //表格底部显示分页条
            sidePagination: "server",
            escape: false, //启动转义字符
            pageSize: 10, //每页显示多少条数据
            pageNumber: 1, //初始化翻页的页码
            pageList: [10, 25, 50, 100],
            queryParamsType: '',//设置请求参数格式
            queryParams: function queryParams(params) {   //设自定义查询参数
                var param = {
                    pageSize: params.pageSize,   //每页多少条数据
                    pageNo: params.pageNumber, // 页码
                };
                var formSerial = {};
                $($("#searchForm").serializeArray()).each(function () {
                    formSerial[this.name] = this.value;
                });
                // var fromValue = JSON.stringify(formSerial);
                Object.assign(param, formSerial);
                return param;
            },
            columns: [
                {
                    checkbox: true,
                    visible: true                  //是否显示复选框
                },
                {field: 'id', title: 'id'},
                {field: 'project.name', title: '所属项目'},
                {field: 'name', title: '功能名称'},
                {field: 'description', title: '功能描述'},
                {field: 'operator', title: '操作', formatter: 'operateFormatter'}
            ]
        });
    });

    // 格式化按钮
    function operateFormatter(value, row, index) {
        var arr = [];

        var viewUrl = pathPrefix + '/view' + '?id=' + row.id;
        var view = '<a href="' + viewUrl + '"  class="btn btn-info btn-xs"><i class="fa fa-search-plus"></i> 查看</a> \n';

        var updateUrl = pathPrefix + '/form' + '?id=' + row.id;
        var update = '<a href="' + updateUrl + '"   class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 修改</a> \n';

        var delUrl = pathPrefix + '/delete?id=' + row.id;
        // var del = '<a href="#"  class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a> \n';
        var del = '<a href="' + delUrl + '" onclick="return confirmx(\'确定删除吗？\', this.href)" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a> \n';

        // arr.push(view);
        arr.push(update);
        arr.push(del);
        return arr.join('');
    }
</script>
</body>
</html>